import {
	defineStore
} from 'pinia';

export const useUserStore = defineStore('user', {
	state: () => {
		return {
			user: {},
			token: "",
			clientId: null,
			currentAreaId: null,
		};
	},
	actions: {
		storeUser(user) {
			this.user = user
			uni.setStorageSync('user', JSON.stringify(user))
		},
		storeToken(token) {
			this.token = token
			uni.setStorageSync("token", token)
		},
		getUser() {
			//判断本地存储中有没有
			if (uni.getStorageSync("user")) {
				return JSON.parse(uni.getStorageSync("user"))
			} else {
				return {}
			}
		},
		storeCurrentArea(area_id) {
			uni.setStorageSync("area_id", area_id)
			this.currentAreaId = area_id
		},
		getCurrentArea() {
			return uni.getStorageSync("area_id")
		}
	},
});